home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Extensions / Imaging / PIL / ImageDraw.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  1.8 KB  |  80 lines

  1. #
  2. # The Python Imaging Library
  3. # $Id: ImageDraw.py,v 1.1.1.2 1999/01/13 09:40:25 sjoerd Exp $
  4. #
  5. # drawing interface operations
  6. #
  7. # History:
  8. # 96-04-13 fl    Created (experimental)
  9. # 96-08-07 fl    Filled polygons, ellipses.
  10. # 96-08-13 fl    Added text support
  11. # 98-06-28 fl    Handle I and F images
  12. # 98-12-29 fl    Added arc; use arc primitive to draw ellipses
  13. #
  14. # Copyright (c) Secret Labs AB 1997-98.
  15. # Copyright (c) Fredrik Lundh 1996.
  16. #
  17. # See the README file for information on usage and redistribution.
  18. #
  19.  
  20. import Image
  21. import math
  22.  
  23. class ImageDraw:
  24.  
  25.     def __init__(self, im):
  26.     im.load(1)
  27.     self.im = im.im
  28.     self.image = im
  29.     if im.mode in ("I", "F"):
  30.         self.ink = self.im.draw_ink(1)
  31.     else:
  32.         self.ink = self.im.draw_ink(-1)
  33.     self.fill = 0
  34.     self.font = None
  35.  
  36.     def setink(self, ink):
  37.     self.ink = self.im.draw_ink(ink)
  38.  
  39.     def setfill(self, onoff):
  40.     self.fill = onoff
  41.  
  42.     def setfont(self, font):
  43.     self.font = font
  44.  
  45.     def arc(self, xy, start, end):
  46.     self.im.draw_arc(xy, start, end, self.ink)
  47.  
  48.     def chord(self, xy, start, end):
  49.     self.im.draw_chord(xy, start, end, self.ink, self.fill)
  50.  
  51.     def line(self, xy, xy1 = None):
  52.     if xy1:
  53.         self.im.draw_line(xy, xy1, self.ink)
  54.     else:
  55.         self.im.draw_lines(xy, self.ink)
  56.  
  57.     def pieslice(self, xy, start, end):
  58.     self.im.draw_pieslice(xy, start, end, self.ink, self.fill)
  59.  
  60.     def point(self, xy):
  61.     self.im.draw_points(xy, self.ink)
  62.  
  63.     def polygon(self, xy):
  64.     self.im.draw_polygon(xy, self.ink, self.fill)
  65.  
  66.     def rectangle(self, xy):
  67.     self.im.draw_rectangle(xy, self.ink, self.fill)
  68.  
  69.     def ellipse(self, xy):
  70.     self.im.draw_ellipse(xy, self.ink, self.fill)
  71.  
  72.     def text(self, xy, text):
  73.     import ImageFont
  74.     if not self.font:
  75.         # FIXME: add font repository
  76.         self.font = ImageFont.load_path("BDF/courR14.pil")
  77.     x, y = xy
  78.     m = self.font.getmask(text)
  79.     self.image.paste(self.ink, (x, y, x + m.size[0], y + m.size[1]), m)
  80.